package kz.home.gui;

import kz.home.db.DBUtils;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import java.util.Hashtable;
import java.util.Vector;

/**
 * <strong>title</strong>
 * <p> describe
 *
 * @author: Danik <br>
 * Date: 03.08.2009  <br>
 * Time: 18:15:17  <br>
 */
public class CinemaForm extends BaseForm{
    protected Vector cinemas;
    protected Command cmd_Select;


    public CinemaForm(BaseForm mainScreen, Display display, Hashtable table,Vector cinemas) {
        super("Список кинотеатров", mainScreen, display, table);
        this.cinemas = cinemas;

        initMap(DBUtils.CINEMAS);
        initCmd();
    }

    protected void initCmd() {
        cmd_Select = new Command("Выбрать", Command.ITEM, 1);
        addCommand(cmd_Select);
    }

    public void addOnScreen() {
        if (cinemas != null) {
            for (int i = 0; i < cinemas.size(); i++) {
                append("" + map.get(cinemas.elementAt(i)) +
                        " [" + cinemas.elementAt(i) + "]" +
                        "\n");
            }
        }
    }

    protected void addToMap(Hashtable map, Vector dataRow) {
        map.put(dataRow.elementAt(0),// id
                "" + dataRow.elementAt(1));// название кинотеатра.;
    }

    public void commandAction(Command command, Displayable displayable) {
        super.commandAction(command, displayable);

        if (command == cmd_Select) {
            setValue("" + cinemas.elementAt(getSelectedIndex()));
            ResultForm form = new ResultForm("Кинотеатр " + map.get(cinemas.elementAt(getSelectedIndex())), this, display, request, 1);
            display.setCurrent(form);
        }
    }

    protected String getParam() {
        return "cin";
    }
}
